﻿@typeparam TItem where TItem : class, new()

<Form @ref="_form" TModel="TItem" Model="Model.Data">
    @if (Model.Fields != null && Model.Fields.Any())
    {
        foreach (var field in Model.Fields)
        {
            var column = field.Column;
            var property = column.GetProperty();
            var required = property.IsRequired();
            <GridRow>
                <GridCol Span="24">
                    <FormItem LabelColSpan="4" Label="@column.Name" Required="required">
                        @field.InputTemplate
                    </FormItem>
                </GridCol>
            </GridRow>
        }
    }
</Form>

@code {
    AntDesign.Internal.IForm _form;

    [Parameter] public FormModel<TItem> Model { get; set; }

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
            Model.OnValidate = _form.Validate;
        base.OnAfterRender(firstRender);
    }
}